namespace SimpleWebServices.Models
{
    using System.Net.Mail;
    using System.Xml.Serialization;
    using Xunit;

    public sealed class EmailFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Email>()
                .DerivesFrom<ValueObject<Email>>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("email")
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Email());
        }

        [Fact]
        public void ctor_string_string()
        {
            Assert.NotNull(new Email("john.doe@example.com", "John Doe"));
        }

        [Fact]
        public void prop_Address()
        {
            Assert.True(new PropertyExpectations(typeof(Email).GetProperty("Address"))
                .XmlAttribute("address")
                .TypeIs<string>()
                .Set(null)
                .Set(string.Empty)
                .Set("john.doe@example.com")
                .Result);
        }

        [Fact]
        public void prop_Key()
        {
            Assert.True(new PropertyExpectations(typeof(Email).GetProperty("Key"))
                .XmlAttribute("key")
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Name()
        {
            Assert.True(new PropertyExpectations(typeof(Email).GetProperty("Name"))
                .XmlAttribute("name")
                .TypeIs<string>()
                .Set(null)
                .Set(string.Empty)
                .Set("John Doe")
                .Result);
        }

        [Fact]
        public void op_ToMailAddress()
        {
            MailAddress expected = new MailAddress("john.doe@example.com", "John Doe");
            MailAddress actual = new Email("john.doe@example.com", "John Doe").ToMailAddress();

            Assert.Equal<MailAddress>(expected, actual);
        }
    }
}